import 'dart:io';

import 'package:bit_fury/http/http_request.dart';

import '../../model/base_response.dart';

abstract class BaseApiService {
  /// 发起GET请求
  Future<BaseResponse<T>> get<T>(String path, {
    Map<String, dynamic>? params,
    String? baseurl,
    bool showLoading = false,
    T Function(dynamic)? fromJsonT,
  }) async {
    return await HttpRequest.request<T>(
      Method.GET,
      path,
      params: params,
      baseurl: baseurl,
      isJson: false,
      showLoading: showLoading,
      fromJsonT: fromJsonT,
    );
  }

  /// 发起POST请求
  Future<BaseResponse<T>> post<T>(String path, {
    Map<String, dynamic>? params,
    dynamic data,
    String? baseurl,
    bool showLoading = false,
    T Function(dynamic)? fromJsonT,
  }) async {
    return await HttpRequest.request<T>(
      Method.POST,
      path,
      params: params,
      data: data,
      baseurl: baseurl,
      isJson: true,
      showLoading: showLoading,
      fromJsonT: fromJsonT,
    );
  }
}